03/09/2019
| ID | Age | Group | Treatment | Outcome |
|---|---|---|---|---|
| 47 | Younger | A | Yes | 18.06815 |
| 187 | Younger | B | No | 17.18054 |
| 191 | Younger | B | No | 16.74415 |
| 41 | Younger | A | Yes | 17.85739 |
| 153 | Younger | B | No | 19.01744 |
| 130 | Older | B | Yes | 20.68289 |
ggplot2 is an R package developed by Hadley Wickham
ggplot(data = ... , aes(x = ... , y = ...)) + geom_ ...
ggplot(data = my_data, aes(x = Group, y = Outcome)) + geom_boxplot()
ggplot(data = my_data, aes(x = Group, y = Outcome)) + geom_violin(trim = FALSE)
ggplot(data = my_data, aes(x = Group, y = Outcome)) + geom_jitter(height = 0, width = 0.1)
ggplot(data = my_data, aes(x = Group, y = Outcome, fill = Group)) + geom_boxplot()
ggplot(data = my_data, aes(x = Group, y = Outcome, colour = Group)) + geom_boxplot()
ggplot(data = my_data, aes(x = Group, y = Outcome, colour = Group)) + geom_jitter(height = 0, width = 0.1)
ggplot(data = my_data, aes(x = Group, y = Outcome, colour = Age)) + geom_jitter(height = 0, width = 0.1)
ggplot(data = my_data, aes(x = Group, y = Outcome, fill = Age)) + geom_boxplot()
ggplot(data = my_data, aes(x = Group, y = Outcome,
fill = Group, colour = Group)) +
geom_jitter(height = 0, width = 0.1) +
geom_boxplot(alpha = 0.5, colour = 'black')
labs() argument:ggplot(data = my_data, aes(x = Group, y = Outcome,
fill = Group, colour = Group)) +
geom_jitter(height = 0, width = 0.1) +
geom_boxplot(alpha = 0.5, colour = 'black') +
labs(title = 'This is objectively the best plot',
x = 'Some letters', y = 'How much you should love this plot')
scale argument to change these:ggplot(data = my_data, aes(x = Group, y = Outcome,
fill = Group, colour = Group)) +
geom_jitter(height = 0, width = 0.1) +
geom_boxplot(alpha = 0.5, colour = 'black') +
scale_y_continuous(limits = c(0, 50), breaks = seq(0, 50, by = 5))
diamonds dataset, other good options are mtcars, iris, & starwars datasets.str() or glimpse() function.